
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>list</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <script src="/js/jquery-2.2.4.js" type="text/javascript"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="toolbarDemo">


        <div class="layui-input-inline">
            <input type="text" name="shop_info_name" id="shop_info_name" lay-verify="required" placeholder="根据地址查询" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <button class="layui-btn layui-btn-sm" id="but">搜索</button>
        </div>




    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="save">新增</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="edit" >修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script src="/js/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>

</script>
<script>
    <!--    全局变量-->
    var users;
    // var qwer;
    // var plantid;
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#test'
            ,id:'userTable'
            ,even: true //开启隔行背景
            ,url:'/shopInfo/query'/*tpa=https://www.layuiweb.com/test/table/demo1.json*/
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '用户数据表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'shop_info_id', title:'商品编号', width:130, fixed: 'left', unresize: true, sort: true}
                ,{field:'shop_info_name', title:'商品名称'}
                ,{field:'shop_info_price', title:'商品价格'}
                ,{field:'shop_info_remark', title:'商品备注'}
                ,{field:'create_time', title:'创建时间', templet: "<div>{{layui.util.toDateString(d.time, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
                ,{field:'modify_time', title:'商品排序',templet: "<div>{{layui.util.toDateString(d.time, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
                ,{field:'version', title:'版本号'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                //添加
                case 'save':
                    layer.open({
                        title: '新增',
                        type: 2,
                        area: ['100%', '100%'],
                        content: '/inof/sava.html'
                    })
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //获取要操作的id
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    alert(data.shop_info_id)
                    $.ajax({
                        type: 'post',
                        data: {"shop_info_id":data.shop_info_id},
                        url: "/shopInfo/del",
                        dataType: 'json',
                        success:function (data){
                            if (data.code=="1"){
                                layer.alert("删除成功")
                                window.location.reload();
                            }else {
                                layer.alert("删除失败")
                                window.location.reload();
                            }
                        }
                    })
                });
            } else if(obj.event === 'edit'){
                users=data;
                layer.open({
                    title: '修改',
                    type: 2,
                    area: ['75%', '85%'],
                    content: '/inof/upd.html'
                })
            }
        });
        var $=layui.jquery;


        $("#but").click(function (){
            table.reload('userTable', {
                where:{
                    shop_info_name:$("#shop_info_name").val()
                }
            });
        })
    });


</script>

</body>
</html>
